<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Jialeo\LaravelSchemaExtend\Schema;

class AlterAddFaqSortIndex extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // Add index for chat_group_faq table
        Schema::table('chat_group_faq', function (Blueprint $table) {

            $table->unsignedInteger('sortDateTimestamp')->default(0)->comment('排序时间')->after("sort");
            $table->string('description', 10000)->comment('详细描述')->after("desc");
            $table->unsignedInteger('sortScore')->comment('排序分数 一级 10000, 二级 100 三级 1')->after("desc");

            $table->index('sort', 'chat_group_faq_sort_index');
            $table->index('sortDateTimestamp', 'chat_group_faq_sort_date_timestamp_index');
        });


        \App\Models\ChatGroup\ChatGroupFAQModel::query()->update([
            'sort'              => 0,
            'sortDateTimestamp' => time(),
        ]);


    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::table('chat_group_faq', function (Blueprint $table) {
            $table->dropIndex('chat_group_faq_sort_index');
            $table->dropIndex('chat_group_faq_sort_date_timestamp_index');
            $table->dropColumn('sortDateTimestamp');
            $table->dropColumn('description');
            $table->dropColumn('sortScore');
        });
    }
}
